﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CoreLib.BusinessLogic;

namespace RKMSikraKulingram.Data
{
    public sealed class PersonDetailsPost
    {
        # region Public Properties

        # region First Person

        private string _title1 = "";
        public string Title1
        {
            get
            {
                return _title1;
            }
            set { _title1 = value; }
        }

        private string _firstName1 = "";
        public string FirstName1
        {
            get
            {
                return _firstName1;
            }
            set { _firstName1 = value; }
        }

        private string _lastName1 = "";
        public string LastName1
        {
            get
            {
                return _lastName1;
            }
            set { _lastName1 = value; }
        }

        public string Name1
        {
            get { return _title1 + " " + _firstName1 + " " + _lastName1; }
        }

        private string _addressLine11 = "";
        public string AddressLine11
        {
            get
            {
                return _addressLine11;
            }
            set { _addressLine11 = value; }
        }

        private string _addressLine12 = "";
        public string AddressLine12
        {
            get
            {
                return _addressLine12;
            }
            set { _addressLine12 = value; }
        }

        private string _addressLine13 = "";
        public string AddressLine13
        {
            get
            {
                return _addressLine13;
            }
            set { _addressLine13 = value; }
        }

        private string _addressLine14 = "";
        public string AddressLine14
        {
            get
            {
                return _addressLine14;
            }
            set { _addressLine14 = value; }
        }

        public string Address1
        {
            get { return _addressLine11 + "\n" + _addressLine12 + "\n" + _addressLine13 + "\n" + _addressLine14; }
        }

        private string _postalCode1 = "";
        public string PostalCode1
        {
            get
            {
                return _postalCode1;
            }
            set { _postalCode1 = value; }
        }

        private string _country1 = "";
        public string Country1
        {
            get
            {
                return _country1;
            }
            set { _country1 = value; }
        }

        # endregion

        # region Second Person

        private string _title2 = "";
        public string Title2
        {
            get
            {
                return _title2;
            }
            set { _title2 = value; }
        }

        private string _firstName2 = "";
        public string FirstName2
        {
            get
            {
                return _firstName2;
            }
            set { _firstName2 = value; }
        }

        private string _lastName2 = "";
        public string LastName2
        {
            get
            {
                return _lastName2;
            }
            set { _lastName2 = value; }
        }

        public string Name2
        {
            get { return _title2 + " " + _firstName2 + " " + _lastName2; }
        }

        private string _addressLine21 = "";
        public string AddressLine21
        {
            get
            {
                return _addressLine21;
            }
            set { _addressLine21 = value; }
        }

        private string _addressLine22 = "";
        public string AddressLine22
        {
            get
            {
                return _addressLine22;
            }
            set { _addressLine22 = value; }
        }

        private string _addressLine23 = "";
        public string AddressLine23
        {
            get
            {
                return _addressLine23;
            }
            set { _addressLine23 = value; }
        }

        private string _addressLine24 = "";
        public string AddressLine24
        {
            get
            {
                return _addressLine24;
            }
            set { _addressLine24 = value; }
        }

        public string Address2
        {
            get { return _addressLine21 + "\n" + _addressLine22 + "\n" + _addressLine23 + "\n" + _addressLine24; }
        }

        private string _postalCode2 = "";
        public string PostalCode2
        {
            get
            {
                return _postalCode2;
            }
            set { _postalCode2 = value; }
        }

        private string _country2 = "";
        public string Country2
        {
            get
            {
                return _country2;
            }
            set { _country2 = value; }
        }

        # endregion

        //# region Third Person

        //private string _title3 = "";
        //public string Title3
        //{
        //    get
        //    {
        //        return _title3;
        //    }
        //    set { _title3 = value; }
        //}

        //private string _firstName3 = "";
        //public string FirstName3
        //{
        //    get
        //    {
        //        return _firstName3;
        //    }
        //    set { _firstName3 = value; }
        //}

        //private string _lastName3 = "";
        //public string LastName3
        //{
        //    get
        //    {
        //        return _lastName3;
        //    }
        //    set { _lastName3 = value; }
        //}

        //public string Name3
        //{
        //    get { return _title3 + " " + _firstName3 + " " + _lastName3; }
        //}

        //private string _addressLine31 = "";
        //public string AddressLine31
        //{
        //    get
        //    {
        //        return _addressLine31;
        //    }
        //    set { _addressLine31 = value; }
        //}

        //private string _addressLine32 = "";
        //public string AddressLine32
        //{
        //    get
        //    {
        //        return _addressLine32;
        //    }
        //    set { _addressLine32 = value; }
        //}

        //private string _addressLine33 = "";
        //public string AddressLine33
        //{
        //    get
        //    {
        //        return _addressLine33;
        //    }
        //    set { _addressLine33 = value; }
        //}

        //private string _addressLine34 = "";
        //public string AddressLine34
        //{
        //    get
        //    {
        //        return _addressLine34;
        //    }
        //    set { _addressLine34 = value; }
        //}

        //public string Address3
        //{
        //    get { return _addressLine33 + "\n" + _addressLine32 + "\n" + _addressLine33 + "\n" + _addressLine34; }
        //}

        //private string _postalCode3 = "";
        //public string PostalCode3
        //{
        //    get
        //    {
        //        return _postalCode3;
        //    }
        //    set { _postalCode3 = value; }
        //}

        //private string _country3 = "";
        //public string Country3
        //{
        //    get
        //    {
        //        return _country3;
        //    }
        //    set { _country3 = value; }
        //}

        //# endregion

        # endregion
    }

    public sealed class PersonDetailsPostCollection
    { 
        # region Private Data Members

        private CoreLib.DAL.PersonDetailsPost[] _personDetailsPostList = null;

        # endregion

        # region Public Constructors

        public PersonDetailsPostCollection() 
        {
            RefreshList();
        }

        # endregion

        # region Public Methods

        private void RefreshList()
        {
            _personDetailsPostListLocal.Clear();
            _personDetailsPostList = CommonBLL.CreateCommonBLL().GetPersonDetailPostList();
            populatePersonDetailsListLocal();
        }

        # endregion

        # region Public Data Members

        private List<PersonDetailsPost> _personDetailsPostListLocal = new List<PersonDetailsPost>();
        public List<PersonDetailsPost> PersonDetailsPostList
        {
            get { return _personDetailsPostListLocal; }
            set { _personDetailsPostListLocal = value; }
        }

        # endregion

        # region Private Methods

        private void populatePersonDetailsListLocal()
        {
            if (null == _personDetailsPostList || _personDetailsPostList.Length == 0)
                return;

            int i = 0;
            bool entered = false;
            PersonDetailsPost personDetailPostLocal = new PersonDetailsPost(); ;
            CoreLib.DAL.PersonDetailsPost personDetailPost;
            while ( i < _personDetailsPostList.Length )
            {
                entered = true;

                personDetailPostLocal = new PersonDetailsPost();

                personDetailPost = _personDetailsPostList[i];
                personDetailPostLocal.Title1 = personDetailPost.Title;
                personDetailPostLocal.FirstName1 = personDetailPost.FirstName;
                personDetailPostLocal.LastName1 = personDetailPost.LastName;
                personDetailPostLocal.AddressLine11 = personDetailPost.AddressLine1;
                personDetailPostLocal.AddressLine12 = personDetailPost.AddressLine2;
                personDetailPostLocal.AddressLine13 = personDetailPost.AddressLine3;
                personDetailPostLocal.AddressLine14 = personDetailPost.AddressLine4;
                personDetailPostLocal.PostalCode1 = personDetailPost.PostalCode;
                personDetailPostLocal.Country1 = personDetailPost.Country;

                i++;
                if (i >= _personDetailsPostList.Length)
                    break;
                personDetailPost = _personDetailsPostList[i];
                personDetailPostLocal.Title2 = personDetailPost.Title;
                personDetailPostLocal.FirstName2 = personDetailPost.FirstName;
                personDetailPostLocal.LastName2 = personDetailPost.LastName;
                personDetailPostLocal.AddressLine21 = personDetailPost.AddressLine1;
                personDetailPostLocal.AddressLine22 = personDetailPost.AddressLine2;
                personDetailPostLocal.AddressLine23 = personDetailPost.AddressLine3;
                personDetailPostLocal.AddressLine24 = personDetailPost.AddressLine4;
                personDetailPostLocal.PostalCode2 = personDetailPost.PostalCode;
                personDetailPostLocal.Country2 = personDetailPost.Country;

                _personDetailsPostListLocal.Add(personDetailPostLocal);
                entered = false;

                i++;
            }
            if (entered)
                _personDetailsPostListLocal.Add(personDetailPostLocal);

        }

        # endregion
    }
}
